﻿using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Agr.CQRS.Domain.Events;

namespace Agr.CQRS.Domain
{
    public class Entity
    {
        protected internal Aggregate Aggregate;
        protected internal int EntityNumber; //unique in aggregate

        protected void HandleNewEvent(DomainEvent ev)
        {
            //this event was created locally, so fill in the default properties
            ev.AggregateRootId = Aggregate.AggregateRoot.Id;
            ev.Version = Aggregate.AggregateRoot.Version + 1; //the version after applying this event
            ev.Entitynumber = EntityNumber;

            Aggregate.Handle(ev);
        }
    }
}
